import { getColorInfo } from '@/common/echarts/color/line'
import { deepClone } from '@/utils/index'

export function getLineOptions(data) {
  const legend = deepClone(data).map((el) => {
    return el.groupName
  })
  const xAxis = deepClone(data[0].items).map((el) => {
    return el.time
  })
  const series = data.map((el, index: number) => {
    const itemData = el.items.map((item) => {
      return item.value
    })
    const colorInfo = getColorInfo(index)
    return {
      name: el.groupName,
      type: 'line',
      barWidth: 35,
      color: colorInfo.color,
      smooth: true,
      stack: 'Total',
      areaStyle: {
        color: {
          type: 'linear',
          x: 0,
          y: 0,
          x2: 0,
          y2: 1,
          colorStops: colorInfo.colorStops,
        },
      },
      emphasis: {
        focus: 'series',
      },
      data: itemData,
    }
  })
  const options = {
    legend: legend,
    xAxis: xAxis,
    series: series,
    pre_cycle: {
      count: {
        data: 776,
      },
      price: {
        data: '6524584.09',
      },
    },
    cycle: {
      count: {
        data: 561,
        percent: 27.71,
        is_plus: -1,
      },
      price: {
        data: '5604097.24',
        percent: 14.11,
        is_plus: -1,
      },
    },
  }
  return options
}
